int libxl_domain_build(struct libxl_ctx *ctx, libxl_domain_build_info *info, uint32_t domid, libxl_domain_build_state *state)
{
char **vments = NULL, **localents = NULL;
- int i;
+ int i, ret;
+
+ ret = build_pre(ctx, domid, info, state);
+ if (ret) goto out;
- build_pre(ctx, domid, info, state);
if (info->hvm) {
- build_hvm(ctx, domid, info, state);
+ ret = build_hvm(ctx, domid, info, state);
+ if (ret) goto out;
+
vments = libxl_calloc(ctx, 5, sizeof(char *));
vments[0] = "rtc/timeoffset";
vments[1] = (info->u.hvm.timeoffset) ? info->u.hvm.timeoffset : "";
vments[2] = "image/ostype";
vments[3] = "hvm";
} else {
- build_pv(ctx, domid, info, state);
+ ret = build_pv(ctx, domid, info, state);
+ if (ret) goto out;
+
vments = libxl_calloc(ctx, 9, sizeof(char *));
i = 0;
vments[i++] = "image/ostype";
vments[i++] = (char*) info->u.pv.cmdline;
}
}
- build_post(ctx, domid, info, state, vments, localents);
- return 0;
+ ret = build_post(ctx, domid, info, state, vments, localents);
+out:
+ return ret;
}
int libxl_domain_restore(struct libxl_ctx *ctx, libxl_domain_build_info *info,
libxl_device_model_info *dm_info)
{
char **vments = NULL, **localents = NULL;
- int i;
+ int i, ret;
+
+ ret = build_pre(ctx, domid, info, state);
+ if (ret) goto out;
+
+ ret = restore_common(ctx, domid, info, state, fd);
+ if (ret) goto out;
- build_pre(ctx, domid, info, state);
- restore_common(ctx, domid, info, state, fd);
if (info->hvm) {
vments = libxl_calloc(ctx, 5, sizeof(char *));
vments[0] = "rtc/timeoffset";
vments[i++] = (char*) info->u.pv.cmdline;
}
}
- build_post(ctx, domid, info, state, vments, localents);
+ ret = build_post(ctx, domid, info, state, vments, localents);
+ if (ret) goto out;
+
if (info->hvm)
asprintf(&(dm_info->saved_state), "/var/lib/xen/qemu-save.%d", domid);
else
dm_info->saved_state = NULL;
-
- return 0;
+out:
+ return ret;
}
int libxl_domain_resume(struct libxl_ctx *ctx, uint32_t domid)
int num_disks = 0, num_vifs = 0, num_pcidevs = 0, num_vfbs = 0, num_vkbs = 0;
int i, fd;
int need_daemon = 1;
+ int ret;
libxl_device_model_starting *dm_starting = 0;
libxl_waiter *w1 = NULL, *w2 = NULL;
memset(&dm_info, 0x00, sizeof(dm_info));
}
libxl_ctx_set_log(&ctx, log_callback, NULL);
- libxl_domain_make(&ctx, &info1, &domid);
+
+ ret = libxl_domain_make(&ctx, &info1, &domid);
+ if (ret) {
+ fprintf(stderr, "cannot make domain: %d\n", ret);
+ return;
+ }
if (!restore_file || !need_daemon) {
if (dm_info.saved_state) {
free(dm_info.saved_state);
dm_info.saved_state = NULL;
}
- libxl_domain_build(&ctx, &info2, domid, &state);
+ ret = libxl_domain_build(&ctx, &info2, domid, &state);
} else {
int restore_fd;
restore_fd = open(restore_file, O_RDONLY);
- libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
+ ret = libxl_domain_restore(&ctx, &info2, domid, restore_fd, &state, &dm_info);
close(restore_fd);
}
+ if (ret) {
+ fprintf(stderr, "cannot (re-)build domain: %d\n", ret);
+ return;
+ }
+
for (i = 0; i < num_disks; i++) {
disks[i].domid = domid;
- libxl_device_disk_add(&ctx, domid, &disks[i]);
+ ret = libxl_device_disk_add(&ctx, domid, &disks[i]);
+ if (ret) {
+ fprintf(stderr, "cannot add disk %d to domain: %d\n", i, ret);
+ return;
+ }
}
for (i = 0; i < num_vifs; i++) {
vifs[i].domid = domid;
- libxl_device_nic_add(&ctx, domid, &vifs[i]);
+ ret = libxl_device_nic_add(&ctx, domid, &vifs[i]);
+ if (ret) {
+ fprintf(stderr, "cannot add nic %d to domain: %d\n", i, ret);
+ return;
+ }
}
if (info1.hvm) {
dm_info.domid = domid;